from PySide2 import QtGui, QtCore, QtWidgets
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *
import sys
import random


class Demo(QWidget):
    def __init__(self, parent=None):
        super(Demo, self).__init__(parent)
        self.setWindowTitle('使用QPainter绘制图像')
        self.resize(300, 120)

    def paintEvent(self, event):
        painter = QPainter(self)
        # painter.drawPixmap(10, 10, QPixmap('路飞.jpg'))     # 默认大小
        painter.drawPixmap(50, 30, 200, 100, QPixmap('路飞.jpg'))     # 指定大小


if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = Demo()
    demo.show()
    sys.exit(app.exec_())

